# Contributor: Ben Allen <bensallen@me.com>
# Maintainer: Peter Shkenev <santurysim@gmail.com>
pkgname=virtualbox-guest-additions
pkgver=6.1.34
pkgrel=0
pkgdesc="VirtualBox Addtions userland components"
arch='x86 x86_64'
url='https://virtualbox.org/'
license="GPL custom"
install="$pkgname.pre-install"
makedepends="sed kbuild lvm2-dev yasm nasm zlib-dev openssl1.1-compat-dev curl-dev
	libxslt libxrandr-dev libxt-dev libxmu-dev linux-pam-dev"
subpackages="$pkgname-x11 $pkgname-openrc"
source="https://download.virtualbox.org/virtualbox/$pkgver/VirtualBox-$pkgver.tar.bz2
	futimens.patch
	musl-no-glibc.patch
	musl-fix-stat-nsec.patch
	musl-off_t.patch
	glibc-symvers.patch
	VBoxClient.patch
	virtualbox-guest-additions-localconfig
	$pkgname.initd
	virtualbox-drm-client.initd
	"

builddir="$srcdir"/VirtualBox-$pkgver

prepare() {
	default_prepare
	rm -rf $builddir/kBuild/bin $builddir/tools
	cp $srcdir/$pkgname-localconfig LocalConfig.kmk
}

build() {
	./configure --nofatal \
		--disable-dbus \
		--disable-xpcom \
		--disable-sdl-ttf \
		--disable-pulse \
		--disable-alsa \
		--disable-kmods \
		--build-headless
	# shellcheck disable=SC1091
	. ./env.sh
	# Build Guest Additions
	kmk KBUILD_VERBOSE=2
}

package() {
	install -v -Dm755 "$builddir"/out/linux.*/release/bin/additions/VBoxService "$pkgdir/usr/sbin/VBoxService"
	install -v -Dm755 "$builddir"/out/linux.*/release/bin/additions/VBoxControl "$pkgdir/usr/bin/VBoxControl"
	# mount.vboxsf needs to be in /sbin for "mount -t vboxsf..." to work.
	install -v -Dm755 "$builddir"/out/linux.*/release/bin/additions/mount.vboxsf "$pkgdir/sbin/mount.vboxsf"
	install -v -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

x11() {
	install -v -Dm755 "$builddir"/out/linux.*/release/bin/additions/VBoxClient "$subpkgdir/usr/sbin/VBoxClient"
	install -v -Dm755 "$builddir"/out/linux.*/release/bin/additions/VBoxDRMClient "$subpkgdir/usr/sbin/VBoxDRMClient"
	install -v -Dm755 "$srcdir"/virtualbox-drm-client.initd "$subpkgdir"/etc/init.d/virtualbox-drm-client
}

sha512sums="
46d63a9fd9df76af654af59fab5cf555858bc2c4b5dc34e2378d85ae784e6380b6def4aab06909a9b5e114a7297269f90cfb2c3d8d6529b423d703afbad18c64  VirtualBox-6.1.34.tar.bz2
1da850bc30399ecde501eba5403ef1add1ae108d38394b01cd7f5cdf0462b855793d564d3adc1f770983b36529d77f3f7b0269fb65152468084a0a44c38e1638  futimens.patch
b1c47cb910ac751df7bd4bc10c5501e91d88a9b3e4fe181b02755d433df8e89a160a38422912266f0cc51ba0c09854dad513ba6f2634fc76c59cee7989b259eb  musl-no-glibc.patch
2c329085915f0ffa43828a14d8b29d0d876e48e18a0190ad146cd0731af7eca11cdf41d2e533c9cc73aa75506b9b91e3a08f2272cd8884e0d929722730b99862  musl-fix-stat-nsec.patch
09a0b5643e5c7d9e878131c5eb5abdec4f3e0626e1e7407dcbe9b295c8f0df972a4f3d43d8c3e99ff4f71d5ae4d5fa37e6cae516a780de384778fee71dfdcb26  musl-off_t.patch
2b907920c32b4385e80b81ec755cb0931d3bb1dff23184ddc49e457f9dfafb2ddbd810418c003c3be82433b06de800fce77a07883fa46e51e6870d565a485add  glibc-symvers.patch
9e2da29de4767e1276fb11191641a4f0ecc133a2113b5dd3cc9e17e59cabd8f192d118680d014641b3cd819d6d6faefbf298c1f0891426e261a9b8a8c69c2c52  VBoxClient.patch
05aac36598cda11940a95c72045be78ec0fbcdfe95b7bd390229a85fb576ccfb6b5adcb479b361fa56755bea62deba4112b997c802d230c5f011c5a67e0c8f91  virtualbox-guest-additions-localconfig
ad6ff256def558f5c6b772c62a3e7a6ccd067ae208491e02ce6738a501d02bcac214056825b804c19fd21b33f3752c62bd8572eb8764f6c5eb10534fa668bd38  virtualbox-guest-additions.initd
44c900a4e96cde88521afaa3604a7e1fa28666196de2f86de02ef7e96d2a64c00f852f9ffb2d77be3a14e11d857d5baf37dec38dfce33ddef8e5518efd7532ed  virtualbox-drm-client.initd
"
